/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.analysis.businesspartner.model;

import cn.ekuma.epos.analysis.businesspartner.CustomerPaymentsEntry;

import com.openbravo.format.Formats;

import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.util.RoundUtils;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Administrator
 */
public class CustomerPaymentsTableModel extends AbstractTableModel{
   List<CustomerPaymentsEntry> rows;
   List<String> orderTypeColumn,paymentColumn;

    public CustomerPaymentsTableModel() {
        rows=new ArrayList();
        orderTypeColumn=new ArrayList();
        paymentColumn=new ArrayList();
    }

    public int getRowCount() {
       return  rows.size();
    }

    public static String[] COLUMNS={
        AppLocal.getIntString("label.name")
    };

    public int getColumnCount() {
        return COLUMNS.length+orderTypeColumn.size()*paymentColumn.size();
    }

    @Override
    public String getColumnName(int column) {
       if(column<COLUMNS.length)
            return COLUMNS[column];
       String orderType=orderTypeColumn.get((column-COLUMNS.length)%(orderTypeColumn.size()*paymentColumn.size()));
       String payment=AppLocal.getIntString("transpayment." + paymentColumn.get((column-COLUMNS.length)%orderTypeColumn.size()));
       return orderType+"/"+payment;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        CustomerPaymentsEntry entry=rows.get(rowIndex);
        if(columnIndex==0)
            return entry.getName();
        String orderType=orderTypeColumn.get((columnIndex-COLUMNS.length)%(orderTypeColumn.size()*paymentColumn.size()));
        String payment=paymentColumn.get((columnIndex-COLUMNS.length)%orderTypeColumn.size());
        return RoundUtils.round(entry.getPaymentTotal(orderType, payment));
    }
    
    

    @Override
	public Class<?> getColumnClass(int columnIndex) {
    	if(columnIndex>0)
			return Double.class;
		return super.getColumnClass(columnIndex);
	}

	public void resert(List<CustomerPaymentsEntry> rows,List<String> orderTypeColumn,List<String> paymentColumn){
         this.rows=rows;
         this.orderTypeColumn=orderTypeColumn;
         this.paymentColumn=paymentColumn;
         fireTableStructureChanged();
    }

}
